package com.jse;

import java.util.Set;

import javax.servlet.MultipartConfigElement;
import javax.servlet.ServletContainerInitializer;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.SessionTrackingMode;
import javax.servlet.annotation.HandlesTypes;

/**
 * 启动
 * 
 * @author Administrator
 *
 */
@HandlesTypes(WebApplicationInitializer.class)
public class JseInitializer implements ServletContainerInitializer {

	@Override
	public void onStartup(Set<Class<?>> webApplicationInitializers, ServletContext sc) throws ServletException {
		javax.servlet.ServletRegistration.Dynamic jseServlet=sc.addServlet("jseServlet",new JseServlet());
		String str = sc.getRealPath("/").replace("\\", "/");
        String webPath = str.substring(0, str.indexOf("tomcat") + 7) + "webapps/";
        jseServlet.setLoadOnStartup(0);
		jseServlet.setMultipartConfig(new MultipartConfigElement(webPath+"upload/temp", 20971520, 4194304, 0));
		jseServlet.addMapping("/");
		Set<SessionTrackingMode> set=Set.of(SessionTrackingMode.COOKIE);
		sc.getSessionCookieConfig().setMaxAge(31536000);
		sc.setSessionTrackingModes(set);
		sc.getServletRegistration("default").addMapping("/js/*","/assets/*","/css/*","/images/*","/img/*",
				"*.jsp","*.png","*.gif","*.jpg","*.jpeg","*.bmp","*.js","*.map",
		        "*.css","*.jspx","*.jpeg","*.htm","*.xhtml","*.mp3","*.mp4","*.ico","*.ttf","*.svg","*.jar","*.woff","*.eot");
		Jse.setSc(sc);
	}

}
